package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.mystery;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Vec3d;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class AssassinateSkill extends BaseSkill {

    public AssassinateSkill(int level){super(level);}

    public AssassinateSkill(NbtCompound nbtCompound){super(nbtCompound);}

    public AssassinateSkill(){
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setCooldown(100);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        return "瞬移到目标身后";
    }

    @Override
    public boolean canUseAbility(MobEntity mobEntity) {
        return mobEntity.world.getTime()>getSkilltime();
    }

    public SkillRarity getSkillRarity(){return SkillRarity.Mystery;}

    @Override
    public boolean onAbilityUse(MobEntity mobEntity) {
        LivingEntity target = mobEntity.getTarget();
        if(canUseAbility(mobEntity) && target != null)
        {
            Vec3d vec3d = target.getRotationVec(1.0F).normalize();
            mobEntity.teleport(target.getX()-vec3d.x,target.getY()+0.1f,target.getZ()-vec3d.z);
            setSkilltime(mobEntity.world.getTime()+getCooldown()-getSkillLevel()*5);
        }
        return true;
    }
}
